package com.member.shop.service.impl;

import com.member.common.utils.DateUtils;
import com.member.shop.domain.SysBizIntegralConfig;
import com.member.shop.mapper.SysBizIntegralConfigMapper;
import com.member.shop.service.ISysBizIntegralConfigService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * 积分配置Service业务层处理
 *
 * @author thomas
 * @date 2024-05-21
 */
@Service
public class SysBizIntegralConfigServiceImpl implements ISysBizIntegralConfigService {
    @Resource
    private SysBizIntegralConfigMapper sysBizIntegralConfigMapper;

    /**
     * 查询积分配置
     *
     * @param id 积分配置主键
     * @return 积分配置
     */
    @Override
    public SysBizIntegralConfig selectSysBizIntegralConfigById(Long id) {
        return sysBizIntegralConfigMapper.selectSysBizIntegralConfigById(id);
    }

    @Override
    public SysBizIntegralConfig selectSysBizIntegralConfigByTypeCode(String typeCode, Long tenantId) {
        SysBizIntegralConfig sysBizIntegralConfig = new SysBizIntegralConfig();
        sysBizIntegralConfig.setTypeCode(typeCode);
        sysBizIntegralConfig.setTenantId(tenantId);
        List<SysBizIntegralConfig> sysBizIntegralConfigs = sysBizIntegralConfigMapper.selectSysBizIntegralConfigList(sysBizIntegralConfig);
        if (CollectionUtils.isEmpty(sysBizIntegralConfigs)) {
            return null;
        }
        return sysBizIntegralConfigs.get(0);
    }

    /**
     * 查询积分配置列表
     *
     * @param sysBizIntegralConfig 积分配置
     * @return 积分配置
     */
    @Override
    public List<SysBizIntegralConfig> selectSysBizIntegralConfigList(SysBizIntegralConfig sysBizIntegralConfig) {
        return sysBizIntegralConfigMapper.selectSysBizIntegralConfigList(sysBizIntegralConfig);
    }

    /**
     * 新增积分配置
     *
     * @param sysBizIntegralConfig 积分配置
     * @return 结果
     */
    @Override
    public int insertSysBizIntegralConfig(SysBizIntegralConfig sysBizIntegralConfig) {
        sysBizIntegralConfig.setCreateTime(DateUtils.getNowDate());
        return sysBizIntegralConfigMapper.insertSysBizIntegralConfig(sysBizIntegralConfig);
    }

    /**
     * 修改积分配置
     *
     * @param sysBizIntegralConfig 积分配置
     * @return 结果
     */
    @Override
    public int updateSysBizIntegralConfig(SysBizIntegralConfig sysBizIntegralConfig) {
        sysBizIntegralConfig.setUpdateTime(DateUtils.getNowDate());
        return sysBizIntegralConfigMapper.updateSysBizIntegralConfig(sysBizIntegralConfig);
    }

    /**
     * 批量删除积分配置
     *
     * @param ids 需要删除的积分配置主键
     * @return 结果
     */
    @Override
    public int deleteSysBizIntegralConfigByIds(Long[] ids) {
        return sysBizIntegralConfigMapper.deleteSysBizIntegralConfigByIds(ids);
    }

    /**
     * 删除积分配置信息
     *
     * @param id 积分配置主键
     * @return 结果
     */
    @Override
    public int deleteSysBizIntegralConfigById(Long id) {
        return sysBizIntegralConfigMapper.deleteSysBizIntegralConfigById(id);
    }
}
